$(document).ready(function(){
    updateNav();

    //导航切换
    $(".menuson li").click(function(){
        $(".menuson li.active").removeClass("active");
    });

    //初始化左侧菜单

    $($("#wnav .panel-header").get(0)).trigger("click");
    $($(".menuson li a").get(0)).trigger("click");
});

/**
 *
 */
function updateNav(){
    addNav(menus);
    initLeftMenu();
}

/**
 * 动态加载左侧菜单
 */
function addNav(data){
    $.each(data, function(i, sm) {
        var menulist = "";
        //若2级菜单有子菜单
        if(sm.children != null && sm.children.length > 0){
            menulist += '<div title="'+sm.name+'" data-options="iconCls:'+sm.iconCls+'" ><ul class="menuson">';
            $.each(sm.children, function(j, o) {
                menulist += '<li><cite></cite><a url="'+ CONTEXT_PATH + o.href +'" title="'+ o.name +'" iconCls="'+ o.iconCls +'">'+ o.name +'</a><i></i></li>';
            });
            menulist += '</ul></div>';
        }

        $('#wnav').accordion('add', {
            title : sm.name,
            border: false,
            content : menulist,
            iconCls : sm.iconCls,
            selected: false,
        });
    });
}

/**
 * 初始化左侧菜单
 */
function initLeftMenu(){
    //左侧菜单点击事件
    $(".menuson li").each(function(){
        $(this).click(function(){
            $(".menuson li").removeClass("selected");
            $(this).addClass("selected");
            var url = $(this).find("a").attr("url") + "?prId=" + prId;
            $("#contentView").attr("src", url);
        });
    });
}